package com.cartel.genius.services.ws;

import java.util.List;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.cartel.genius.dao.exceptions.CategoryNotFoundException;
import com.cartel.genius.dao.exceptions.PlaceExistsException;
import com.cartel.genius.dao.exceptions.PlaceNotFoundException;
import com.cartel.genius.dao.exceptions.PlaceParentNotFoundException;
import com.cartel.genius.dto.PlaceTO;
import com.cartel.genius.services.PlaceService;

/**
 * Webservice delegate class for place operations
 * 
 * @author Naresh Reddy
 */
@Path("/")
@Produces( { MediaType.APPLICATION_XML })
public class PlaceServiceDelegate implements PlaceService {
	
	private PlaceService placeService;
	
	public void setPlaceService(PlaceService placeService) {
		this.placeService = placeService;
	}

	@Override
	@PUT
	@Path("/add/root/placeCode/{placeCode}/placeName/{placeName}/categoryName/{categoryName}")	
	public PlaceTO addRootPlace(@PathParam("placeCode") String placeCode, @PathParam("placeName") String placeName, @PathParam("categoryName") String categoryName) throws PlaceExistsException, CategoryNotFoundException {
		return placeService.addRootPlace(placeCode, placeName, categoryName);
	}

	@Override
	@PUT	
	@Path("/add/root/placeCode/{placeCode}/placeName/{placeName}/categoryId/{categoryId}")
	public PlaceTO addRootPlace(@PathParam("placeCode") String placeCode, @PathParam("placeName") String placeName, @PathParam("categoryId") int categoryId) throws PlaceExistsException, CategoryNotFoundException {
		return placeService.addRootPlace(placeCode, placeName, categoryId);
	}

	@Override
	@PUT
	@Path("/add/root/{placeTO}")
	public PlaceTO addRootPlace(@PathParam("placeTO") PlaceTO placeTO) throws PlaceExistsException, CategoryNotFoundException {
		return placeService.addRootPlace(placeTO);
	}

	@Override
	@PUT
	@Path("/add/{placeTO}")
	public PlaceTO addPlace(@PathParam("placeTO") PlaceTO placeTO) throws PlaceExistsException, PlaceParentNotFoundException, CategoryNotFoundException {
		return placeService.addPlace(placeTO);
	}

	@Override
	@PUT
	@Path("/add/places/{placeTOList}")
	public List<PlaceTO> addPlaces(@PathParam("placeTOList") List<PlaceTO> placeTOList) {
		return placeService.addPlaces(placeTOList);
	}

	@Override
	@PUT
	@Path("/add/places/{placeTOList}/parentPlace/{parentPlace}")
	public List<PlaceTO> addPlaces(@PathParam("placeTOList") List<PlaceTO> placeTOList, @PathParam("parentPlace") PlaceTO parentPlace) throws PlaceParentNotFoundException, CategoryNotFoundException {
		return placeService.addPlaces(placeTOList, parentPlace);
	}

	@Override
	@PUT
	@Path("/add/placeName/{placeName}/placeCode/{placeCode}/parentPlaceId/{parentPlaceId}/categoryId/{categoryId}")
	public PlaceTO addPlace(@PathParam("placeName") String placeName, @PathParam("placeCode") String placeCode, @PathParam("parentPlaceId") int parentPlaceId, @PathParam("categoryId") int categoryId) throws PlaceExistsException, PlaceParentNotFoundException, CategoryNotFoundException {
		return placeService.addPlace(placeName, placeCode, parentPlaceId, categoryId);
	}

	@Override
	@PUT
	@Path("/add/placeName/{placeName}/placeCode/{placeCode}/parentPlaceCode/{parentPlaceCode}/categoryId/{categoryId}")
	public PlaceTO addPlace(@PathParam("placeName") String placeName, @PathParam("placeCode") String placeCode, @PathParam("parentPlaceCode") String parentPlaceCode, @PathParam("categoryId") int categoryId) throws PlaceExistsException, PlaceParentNotFoundException, CategoryNotFoundException {
		return placeService.addPlace(placeName, placeCode, parentPlaceCode, categoryId);
	}

	@Override
	@PUT
	@Path("/add/placeName/{placeName}/placeCode/{placeCode}/parentPlaceId/{parentPlaceId}/categoryName/{categoryName}")
	public PlaceTO addPlace(@PathParam("placeName") String placeName, @PathParam("placeCode") String placeCode, @PathParam("parentPlaceId") int parentPlaceId, @PathParam("categoryName") String categoryName) throws PlaceExistsException, PlaceParentNotFoundException, CategoryNotFoundException {
		return placeService.addPlace(placeName, placeCode, parentPlaceId, categoryName);
	}

	@Override
	@PUT
	@Path("/add/place/placeName/{placeName}/placeCode/{placeCode}/parentPlaceCode/{parentPlaceCode}/categoryName/{categoryName}")
	public PlaceTO addPlace(@PathParam("placeName") String placeName, @PathParam("placeCode") String placeCode, @PathParam("parentPlaceCode") String parentPlaceCode, @PathParam("categoryName") String categoryName) throws PlaceExistsException, PlaceParentNotFoundException, CategoryNotFoundException {
		return placeService.addPlace(placeName, placeCode, parentPlaceCode, categoryName);
	}

	@Override
	@POST
	@Path("/modifyName/placeId/{placeId}/newPlaceName/{newPlaceName}")
	public PlaceTO modifyPlaceName(@PathParam("placeId") int placeId, @PathParam("newPlaceName") String newPlaceName) throws PlaceExistsException, PlaceNotFoundException, CategoryNotFoundException {
		return placeService.modifyPlaceName(placeId, newPlaceName);
	}

	@Override
	@POST
	@Path("/modifyName/placeCode/{placeCode}/newPlaceName/{newPlaceName}")
	public PlaceTO modifyPlaceName(@PathParam("placeCode") String placeCode, @PathParam("newPlaceName") String newPlaceName) throws PlaceExistsException, PlaceNotFoundException, CategoryNotFoundException {
		return placeService.modifyPlaceName(placeCode, newPlaceName);
	}

	@Override
	@POST
	@Path("/modfyCode/oldPlaceCode/{oldPlaceCode}/newPlaceCode/{newPlaceCode}")
	public PlaceTO modifyPlaceCode(@PathParam("oldPlaceCode") String oldPlaceCode, @PathParam("newPlaceCode") String newPlaceCode) throws PlaceExistsException, PlaceNotFoundException, CategoryNotFoundException {
		return placeService.modifyPlaceCode(oldPlaceCode, newPlaceCode);
	}

	@Override
	@POST
	@Path("/modify/placeId/{placeId}/newPlace/{newPlace}")
	public PlaceTO modifyPlace(@PathParam("placeId") int placeId, @PathParam("newPlace") PlaceTO newPlace) throws PlaceExistsException, PlaceNotFoundException, CategoryNotFoundException {
		return placeService.modifyPlace(placeId, newPlace);
	}

	@Override
	@POST
	@Path("/modify/placeCode/{placeCode}/newPlace/{newPlace}")
	public PlaceTO modifyPlace(@PathParam("placeCode") String placeCode, @PathParam("newPlace") PlaceTO newPlace) throws PlaceExistsException, PlaceNotFoundException, CategoryNotFoundException {
		return placeService.modifyPlace(placeCode, newPlace);
	}

	@Override
	@POST
	@Path("/modify/oldPlace/{oldPlace}/newPlace/{newPlace}")
	public PlaceTO modifyPlace(@PathParam("oldPlace") PlaceTO oldPlace, @PathParam("newPlace") PlaceTO newPlace) throws PlaceExistsException, PlaceNotFoundException, CategoryNotFoundException {
		return placeService.modifyPlace(oldPlace, newPlace);
	}

	@Override
	@POST
	@Path("/modifyCategory/placeId/{placeId}/newCategoryId/{newCategoryId}")
	public PlaceTO modifyPlaceCategory(@PathParam("placeId") int placeId, @PathParam("newCategoryId") int newCategoryId) throws PlaceNotFoundException, CategoryNotFoundException, PlaceExistsException {
		return placeService.modifyPlaceCategory(placeId, newCategoryId);
	}

	@Override
	@POST
	@Path("/modifyCategory/placeCode/{placeCode}/newCategoryId/{newCategoryId}")
	public PlaceTO modifyPlaceCategory(@PathParam("placeCode") String placeCode, @PathParam("newCategoryId") int newCategoryId) throws PlaceNotFoundException, CategoryNotFoundException, PlaceExistsException {
		return placeService.modifyPlaceCategory(placeCode, newCategoryId);
	}

	@Override
	@POST
	@Path("/modifyCategory/placeId/{placeId}/categoryName/{categoryName}")
	public PlaceTO modifyPlaceCategory(@PathParam("placeId") int placeId, @PathParam("categoryName") String categoryName) throws PlaceNotFoundException, CategoryNotFoundException, PlaceExistsException {
		return placeService.modifyPlaceCategory(placeId, categoryName);
	}

	@Override
	@POST
	@Path("/modifyCategory/placeCode/{placeCode}/categoryName/{categoryName}")
	public PlaceTO modifyPlaceCategory(@PathParam("placeCode") String placeCode, @PathParam("categoryName") String categoryName) throws PlaceNotFoundException, CategoryNotFoundException, PlaceExistsException {
		return placeService.modifyPlaceCategory(placeCode, categoryName);
	}

	@Override
	@POST
	@Path("/modifyParent/placeId/{placeId}/parentPlaceId/{parentPlaceId}")
	public PlaceTO modifyPlaceParent(@PathParam("placeId") int placeId, @PathParam("parentPlaceId") int parentPlaceId) throws PlaceNotFoundException, PlaceParentNotFoundException {
		return placeService.modifyPlaceParent(placeId, parentPlaceId);
	}

	@Override
	@POST
	@Path("/modifyParent/placeCode/{placeCode}/parentPlaceId/{parentPlaceId}")
	public PlaceTO modifyPlaceParent(@PathParam("placeCode") String placeCode, @PathParam("parentPlaceId") int parentPlaceId) throws PlaceNotFoundException, PlaceParentNotFoundException {
		return placeService.modifyPlaceParent(placeCode, parentPlaceId);
	}

	@Override
	@POST
	@Path("/modifyParent/placeId/{placeId}/parentPlaceCode/{parentPlaceCode}")
	public PlaceTO modifyPlaceParent(@PathParam("placeId") int placeId, @PathParam("parentPlaceCode") String parentPlaceCode) throws PlaceNotFoundException, PlaceParentNotFoundException {
		return placeService.modifyPlaceParent(placeId, parentPlaceCode);
	}

	@Override
	@POST
	@Path("/modifyParent/placeCode/{placeCode}/parentPlaceCode/{parentPlaceCode}")
	public PlaceTO modifyPlaceParent(@PathParam("placeCode") String placeCode, @PathParam("parentPlaceCode") String parentPlaceCode) throws PlaceNotFoundException, PlaceParentNotFoundException {
		return placeService.modifyPlaceParent(placeCode, parentPlaceCode);
	}

	@Override
	@DELETE
	@Path("/remove/placeId/{placeId}")
	public void removePlace(@PathParam("placeId") int placeId) throws PlaceNotFoundException {
		placeService.removePlace(placeId);
	}

	@Override
	@DELETE
	@Path("/remove/placeCode/{placeCode}")
	public void removePlace(@PathParam("placeCode") String placeCode) throws PlaceNotFoundException {
		placeService.removePlace(placeCode);
	}

	@Override
	@GET
	@Path("/get/toCategoryId/{toCategoryId}/placeId/{placeId}")
	public List<PlaceTO> getPlaces(@PathParam("toCategoryId") int toCategoryId, @PathParam("placeId") int placeId) throws PlaceNotFoundException, CategoryNotFoundException {
		return placeService.getPlaces(toCategoryId, placeId);
	}

	@Override
	@GET
	@Path("/get/toCategoryName/{toCategoryName}/placeId/{placeId}")
	public List<PlaceTO> getPlaces(@PathParam("toCategoryName") String toCategoryName, @PathParam("placeId") int placeId) throws PlaceNotFoundException, CategoryNotFoundException {
		return placeService.getPlaces(toCategoryName, placeId);
	}

	@Override
	@GET
	@Path("/get/toCategoryId/{toCategoryId}/placeCode/{placeCode}")
	public List<PlaceTO> getPlaces(@PathParam("toCategoryId") int toCategoryId, @PathParam("placeCode") String placeCode) throws PlaceNotFoundException, CategoryNotFoundException {
		return placeService.getPlaces(toCategoryId, placeCode);
	}

	@Override
	@GET
	@Path("/get/toCategoryName/{toCategoryName}/placeCode/{placeCode}")
	public List<PlaceTO> getPlaces(@PathParam("toCategoryName") String toCategoryName, @PathParam("placeCode") String placeCode) throws PlaceNotFoundException, CategoryNotFoundException {
		return placeService.getPlaces(toCategoryName, placeCode);
	}

	@Override
	@GET
	@Path("/get/placeCode/{placeCode}")
	public List<PlaceTO> getPlaces(@PathParam("placeCode") String placeCode) throws PlaceNotFoundException {
		return placeService.getPlaces(placeCode);
	}

	@Override
	@GET
	@Path("/get/placeId/{placeId}")
	public List<PlaceTO> getPlaces(@PathParam("placeId") int placeId) throws PlaceNotFoundException {
		return placeService.getPlaces(placeId);
	}

	@Override
	@GET
	@Path("/get/categoryName/{categoryName}")
	public List<PlaceTO> getPlacesOfCategory(@PathParam("categoryName") String categoryName) throws CategoryNotFoundException {
		return placeService.getPlacesOfCategory(categoryName);
	}

	@Override
	@GET
	@Path("/get/categoryId/{categoryId}")
	public List<PlaceTO> getPlacesOfCategory(@PathParam("categoryId") int categoryId) throws CategoryNotFoundException {
		return placeService.getPlacesOfCategory(categoryId);
	}

}
